package cn.tedu.date;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class DateDemo {
    public static void main(String[] args) {
        //创建Date对象
//        Date date = new Date();
//        System.out.println(date.toString());//date.toString()重写了
        //Tue Oct 27 16:42:44 CST 2020

        //有参构造
//        Date date = new Date(5000);//1s=1000ms
//        System.out.println(date);

        //getTime
//        Date date = new Date();
//        System.out.println(date);
//        long time = date.getTime();
//        System.out.println(time);

        //字符串拼接
//        Date start = new Date();
//        String str = "start";
//        //一次循环创建两个对象 new StringBuilder()  new String
//        //20000个对象
//        for (int i = 0; i <100000 ; i++) {
//            str = str+i+",";//new StringBuilder().append(str).append(i).append(",").toString()
//        }
////        System.out.println(str);
//        Date end = new Date();
//        System.out.println("耗时:"+(end.getTime()-start.getTime())+"ms");
//        Date start = new Date();
//        StringBuilder builder = new StringBuilder("start");//new StringBuilder
//        for (int i = 0; i <10000000  ; i++) {
//            builder.append(i).append(",");
//        }
//        String res = builder.toString();//new String()
////        System.out.println(res);
//        Date end = new Date();
//        System.out.println("耗时:"+(end.getTime()-start.getTime())+"ms");

        //long->Date
//        Date date = new Date();
//        date.setTime(5000);
//        System.out.println(date);

        //Calendar
//        new Calendar();
//        Calendar cal =  Calendar.getInstance();
//        System.out.println(cal);
//        System.out.println(Calendar.YEAR);//1
//        System.out.println(Calendar.MONTH);//2
//        System.out.println(Calendar.DAY_OF_MONTH);//5
        //获取年的值
//        System.out.println(cal.get(Calendar.YEAR));
//        System.out.println(cal.get(Calendar.MONTH)+1);

        //设置日期的值
//        Calendar cal =  Calendar.getInstance();
//        System.out.println(cal.get(Calendar.YEAR));
//        cal.set(Calendar.YEAR,2000);
//        System.out.println(cal);

        //指定出生日期
//        Calendar cal =  Calendar.getInstance();
//        cal.set(2003,2,12);//2003-3-12
//        System.out.println(cal);

        //Calendar->Date
        Calendar cal =  Calendar.getInstance();
//        Date date = cal.getTime();
//        System.out.println(date);

        long time = cal.getTimeInMillis();
        System.out.println(time);
    }
}
